
enum SIZE {
    //% block="29*29"
    1,
    //% block="58*58"
    2
}

enum PIN {
    //% block="HD1"
    2,
    //% block="HD2"
    3,
    //% block="HD3"
    4,
    //% block="HD4"
    5,
    //% block="HD5"
    6
}

enum LED {
    //% block="L1"
    13
}

enum BOOL {
    //% block="true"
    true,
    //% block="false"
    false
}

//% color="#FFAEC8" iconWidth=70 iconHeight=60
namespace FCHD1114 {
    // //% block="ledControlor [LED] onTime1 [T1] offTime2 [T2]" blockType="command"
    // //% LED.shadow="dropdown" LED.options="LED" LED.defl="LED.L1"
    // //% T1.shadow="number" T1.defl="1000"
    // //% T2.shadow="number" T2.defl="1000"
    // export function ledControlor(parameter: any, block: any){
    //     let led = parameter.LED.code
    //     let t1 = parameter.T1.code
    //     let t2 = parameter.T2.code
    //     Generator.addInclude("LED","#include <LED.h>");
    //     Generator.addObject(`myLED`, `LED`, `myLED(${led});`);
    //     Generator.addSetup(`pinMode`, `pinMode(${led},OUTPUT);`);
    //     Generator.addCode(`myLED.on();\n\tdelay(${t1});`);
    //     Generator.addCode(`myLED.off();\n\tdelay(${t2});`);

    // }

    //% block="readOneGraySensor [PIN]" blockType="reporter"
    //% PIN.shadow="dropdown" PIN.options="PIN" PIN.defl="PIN.HD1"
    export function readPin(parameter: any, block: any){
        let pin = parameter.PIN.code;
        Generator.addCode(`digitalRead(${pin})`);

    }

    
    //% block="readGray o1-o5 [PIN1] [PIN2] [PIN3] [PIN4] [PIN5]" blockType="reporter"
    //% PIN1.shadow="number" PIN1.defl="2"
    //% PIN2.shadow="number" PIN2.defl="3"
    //% PIN3.shadow="number" PIN3.defl="4"
    //% PIN4.shadow="number" PIN4.defl="5"
    //% PIN5.shadow="number" PIN5.defl="6"
    export function readGray(parameter: any, block: any){
        // 创建一个数组来存储引脚编号
        let pin1 = parameter.PIN1.code
        let pin2 = parameter.PIN2.code
        let pin3 = parameter.PIN3.code
        let pin4 = parameter.PIN4.code
        let pin5 = parameter.PIN5.code;
        Generator.addInclude("FCHD1114","#include <FCHD1114.h>",true);
        Generator.addObject(`PIN`,`int pins[NUM_SENSORS]={${pin1},${pin2},${pin3},${pin4},${pin5}}`,``);
        // Generator.addSetup(`array`,`pins[5]={${pin1},${pin2},${pin3},${pin4},${pin5}};`);
        Generator.addCode(`readGraySensorArray(pins)`);

    }

    //% block="getError grayValue [grayValue] Scale [scale]" blockType="reporter"
    //% grayValue.shadow="normal" grayValue.defl="0xFF"
    //% scale.shadow="range" scale.params.min=1 scale.params.max=4 scale.defl=1
    export function getError(parameter: any, block: any) {
        let gv = parameter.grayValue.code;
        let sc = parameter.scale.code;
        Generator.addInclude("FCHD1114","#include <FCHD1114.h>",true);
        Generator.addCode(`getError(${gv},${sc})`);

    }

    // //% block="标签测试" blockType="tag"
    // export function tagtest() {}

    // //% block="---"
    // export function noteSep() {}

    // function replace(str :string) {
    //     return str.replace("+", "");
    // }

}
